package com.ashley.queue;

/**
 * @Author ashley
 * @Date 2019/9/11 9:03
 */
public class ArrayQueue {
    private int[] arrInt;//-----����
    private int front;//-----ͷָ��
    private int rear;//-----βָ��

    //��ʼ��
    public ArrayQueue(int size) {
        this.arrInt = new int[size];
        front = 0;
        rear = -1;
    }
    //�ж϶����Ƿ�Ϊ��
    public boolean isEmpty() {
        return front == arrInt.length;
    }

    //�ж϶����Ƿ�����
    public boolean isFull() {
        return arrInt.length - 1 == rear;
    }

    //�ڶ�β����Ԫ��
    public void insert(int item) {
        if (isFull()) {
            throw new RuntimeException("��������");
        }
        arrInt[++rear] = item;
    }

    //��ȡ��ͷԪ��
    public int peekFront() {
        return arrInt[front];
    }

    //��ȡ��βԪ��
    public int peekRear() {
        return arrInt[rear];
    }

    //�Ӷ�ͷ�Ƴ�Ԫ��
    public int remove() {
        if (isEmpty()) {
            throw new RuntimeException("����Ϊ��");
        }
        return arrInt[front++];
    }

}
